package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Orders;
import com.neusoft.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Orders")
@RefreshScope //开启动态刷新
public class OrdersController {
	@Autowired

	private OrdersService ordersService;

	@GetMapping("/OrdersList")
	public CommonResult<List> listOrdersByUserId(Orders orders) throws Exception {
		return new CommonResult<List>(200, "success", ordersService.listOrdersByUserId(orders.getUserId()));
	}

	@PostMapping("/OrdersId")
	public CommonResult<Integer> createOrders(Orders orders) throws Exception {
		return new CommonResult<Integer>(200, "success", ordersService.createOrders(orders));
	}

	@GetMapping("/OrdersId")
	public CommonResult<Orders> getOrderById(Orders orders) throws Exception {
		return new CommonResult<Orders>(200, "success", ordersService.getOrdersById(orders.getOrderId()));
	}

	// 特殊
	@PutMapping("/OrdersId")
	public CommonResult<Integer> updateOrder(Orders orders) throws Exception {
		return new CommonResult<Integer>(200, "success", ordersService.updateOrder(orders));
	}

	@DeleteMapping("/OrdersId")
	public CommonResult<Integer> removeOrders(Orders orders) throws Exception {
		return new CommonResult<Integer>(200, "success", ordersService.removeOrders(orders.getOrderId()));
	}
}